<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
</head>

<body>
    <header class="aui-bar aui-bar-nav" style="background-color: #03a9f4;position:fixed;" id="header">
        <a class="aui-pull-left aui-btn" tapmode onclick="closeWin();">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title" id="title">
            改码绑定关系查询
        </div>
    </header>
    <div class="aui-content aui-margin-b-15" style="margin-top:60px;">
        <ul class="aui-list aui-form-list">
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">产品条码</div>
                    <div class="aui-list-item-input">
                        <input type="text" placeholder="请扫描产品条码" id="barCode" value="" onclick="getIdSelector();">
                    </div>
                </div>
            </li>
        </ul>
        <p></p>
        <p></p>
        <div class="aui-btn aui-btn-info aui-btn-block" onclick="save()">查询</div>
        <div style="background-color:white; height:320px;width: 100%;margin-top:3%;border:solid 1px #D3D3D3;display:block"
            id="tableDiv">
            <table class="table" style='width:100%; font-size:14px;' id="table">
                <tbody id="tbodyHtml2">
                    <tr>
                        <td style="width:23%;text-align:right;">源&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp码:</td>
                        <td id="barCodeY"></td>
                    </tr>
                    <tr>
                        <td style="width:23%;text-align:right;">
                            新&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp码:</td>
                            
                        <td id="barCodeX"></td>
                    </tr>
                    <tr>
                        <td style="width:23%;text-align:right;">改码时间:</td>
                        <td id="bingdingTimeT"></td>
                    </tr>
                    <tr>
                        <td style="width:23%;text-align:right;">产&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp线:</td>
                        <td id="lineCodeT"></td>
                    </tr>
                    
                <tbody>
            </table>
        </div>
    </div>
    <footer class="aui-bar aui-bar-tab" id="footer">
        <div class="aui-bar-tab-item" tapmode id="scan" onclick="doScan()">
            <i class="aui-iconfont aui-icon-scan aui-text-epblue" style="font-size: 1.8rem"></i>
        </div>
    </footer>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript">
    //光标所在id
    var idSelector = "";

    //初始化查询仓库下拉框
    apiready = function () {
        $("#barCode").focus();
        idSelector = "barCode";


    }


   


    // 获取光标所在组件的id
    function getIdSelector() {
        var e = event || window.event;
        var el = e.srcElement || e.target;
        idSelector = el.id;
        $("#" + el.id).select();
    }

    //扫描
    function doScan() {
        var moduleScanner = api.require('moduleScanner');
        var params = {
            top: 150, //扫描窗口的上边距
            width: 250, //扫描窗口的宽
            height: 250, //扫描窗口的高
            useColor: false, //是否使用自己设定的颜色(startColor和endColor),
            //如果不使用设定的颜色就使用默认的那张网格图
            startColor: '#0F08C8FF', //渐变起始颜色
            endColor: '#7F08C8FF', //渐变结束颜色
            animTime: 2200, //扫描动画时间,单位为毫秒
        };
        moduleScanner.toScannerActivityForResult(params, function (ret, err) {
            //alert(ret);扫码的结果都是编码

            //扫描条码
            if (idSelector == 'barCode') {
                $("#barCode").blur();
                $("#barCode").val(ret);
                save()
            }
        });
    }
    //箱号监听回车事件
    $("#barCode").on('keypress', function (e) { //#keyword为input文本框
        var keycode = e.keyCode;
        var tm = $(this).val();
        if (keycode == '13') {
            if (tm != null && tm != "" && tm != undefined) {
                $("#barCode").blur();
                save()
            }
        }
    });




    //保存按钮
    function save() {

        //产品条码
        var barCode = $("#barCode").val();

        //箱码非空校验
        if (barCode == "" || barCode == null || barCode == undefined) {
            api.toast({
                msg: '请扫码产品条码',
                duration: 3000
            });
            return;
        }

        api.showProgress({
            title: '查询中...',
        });
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/ssPrintBarcode";
        var data = {
            values: { ////以表单方式提交参数（JSON对象）
                barCode: barCode, //箱码
                appVersion: api.appVersion,
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 30,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //成功
                if (myobj.code == '0') {
                    api.hideProgress();
                    var map = myobj.data;
                    $("#barCodeY").html(map["barCodeY"]);
                    $("#barCodeX").html(map["barCodeX"]);
                    $("#bingdingTimeT").html(map["bingdingTimeT"]);
                    $("#lineCodeT").html(map["lineCodeT"]);

                    $("#barCode").val("");
                    $("#barCode").focus();
                    idSelector = "barCode";


                } else if (myobj.code == '1') {
                    $("#barCode").val("");
                    $("#barCode").select();
                    idSelector = "barCode";
                    api.hideProgress();
                    clearTabltDiv();
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });


    }

    //清空
    function clearTabltDiv() {
        $("#barCodeY").html("");
        $("#barCodeX").html("");
        $("#bingdingTimeT").html("");
        $("#lineCodeT").html("");
    }






    //返回按钮
    function closeWin() {
        api.closeWin({});
    }
</script>

</html>